home *** CD-ROM | disk | FTP | other *** search
- /* © 1988, Bowers Development Corp. */
- /* ScrollText.c */
-
- #include "Globals.h"
- #include "Cursors.h"
- #include "Scrolling.h"
-
- #include "ScrollText.h"
-
- #define textMargin 4
-
- /*----------*/
- void SetMaxScroll ()
- {
- #define active 0
- #define inactive 255
-
- short textSize;
- short pageSize;
-
- if (cur->vScroll != nil) {
- pageSize = GetCRefCon (cur->vScroll) + 1;
- if (cur->text != nil) {
- textSize = (**(cur->text)).nLines;
- } else {
- textSize = 0;
- }
- if (textSize > pageSize) {
- SetCtlMax (cur->vScroll, textSize - pageSize);
- HiliteControl (cur->vScroll, active);
- } else {
- SetCtlMax (cur->vScroll, 0);
- HiliteControl (cur->vScroll, inactive);
- }
- }
- } /*SetMaxScroll*/
-
- /*----------*/
- void ScrollToBar ()
- {
- short curScroll;
- short newScroll;
- register TEPtr curTE;
-
- if (cur->vScroll != nil) {
- if (cur->text != nil) {
- HLock ((Handle) (cur->text));
- curTE = *(cur->text);
- curScroll = curTE->viewRect.top - curTE->destRect.top;
- newScroll = GetCtlValue (cur->vScroll) * curTE->lineHeight;
- if (newScroll != curScroll) {
- if (curTE->selStart == curTE->selEnd) {
- TEDeactivate (cur->text);
- }
- TEScroll (0, (curScroll - newScroll), cur->text);
- if (curTE->selStart == curTE->selEnd) {
- TEActivate (cur->text);
- }
- }
- HUnlock ((Handle) (cur->text));
- }
- }
- } /*ScrollToBar*/
-
- /*----------*/
- void SetBarToChar (short charNr,
- Boolean toMiddle);
- void SetBarToChar (charNr,
- toMiddle)
- short charNr;
- Boolean toMiddle;
- {
- short lineNr;
- short pageSize;
- register TEPtr curTE;
-
- if (cur->vScroll != nil) {
- curTE = *(cur->text);
- lineNr = 0;
- while (curTE->lineStarts [lineNr + 1] <= charNr) {
- lineNr++;
- }
- if (toMiddle) {
- pageSize = GetCRefCon (cur->vScroll) + 1;
- lineNr = lineNr - (pageSize / 2);
- }
- SetCtlValue (cur->vScroll, lineNr);
- }
- } /*SetBarToChar*/
-
- /*----------*/
- void ScrollToSelection ()
- {
- short topLine;
- short bottomLine;
- short pageSize;
- register TEPtr curTE;
-
- if (cur->vScroll != nil) {
- HLock ((Handle) (cur->text));
- curTE = *(cur->text);
- if (GetCtlMax (cur->vScroll) > 0) {
- topLine = GetCtlValue (cur->vScroll);
- pageSize = GetCRefCon (cur->vScroll) + 1;
- bottomLine = topLine + pageSize - 1;
- if ((curTE->selStart < curTE->lineStarts [topLine])
- || (curTE->selStart > curTE->lineStarts [bottomLine])) {
- SetBarToChar (curTE->selStart, true);
- }
- }
- ScrollToBar ();
- HUnlock ((Handle) (cur->text));
- }
- } /*ScrollToSelection*/
-
- /*----------*/
- void ResizeText ()
- {
- short topLine;
- short topChar;
- short pageSize;
- register TEPtr curTE;
-
- InvalRect (&(curWindow->portRect));
- if (cur->text != nil) {
- SetCursor (&(**watch));
- HLock ((Handle) (cur->text));
- curTE = *(cur->text);
- curTE->viewRect = curWindow->portRect;
- if (cur->vScroll != nil) {
- curTE->viewRect.right = curTE->viewRect.right + 1 - sBarWidth;
- }
- if (cur->hScroll != nil) {
- curTE->viewRect.bottom = curTE->viewRect.bottom + 1 - sBarWidth;
- }
- curTE->destRect = curTE->viewRect;
- InsetRect (&(curTE->destRect), textMargin, 0);
- TECalText (cur->text);
-
- if (cur->vScroll != nil) {
- pageSize = (curTE->viewRect.bottom
- - curTE->viewRect.top) / curTE->lineHeight;
- SetCRefCon (cur->vScroll, pageSize - 1);
- topLine = GetCtlValue (cur->vScroll);
- topChar = curTE->lineStarts [topLine];
- SetMaxScroll ();
- SetBarToChar (topChar, false);
- ScrollToBar ();
- }
- HUnlock ((Handle) (cur->text));
- }
- } /*ResizeText*/
-
- /*----------*/
- pascal Boolean AutoScroll ()
- {
- Point mousePoint;
- Rect viewRect;
- RgnHandle saveClip;
-
- if (cur->vScroll != nil) {
- saveClip = NewRgn ();
- GetClip (saveClip);
- ClipRect (&(curWindow->portRect));
- GetMouse (&mousePoint);
- viewRect = (**(cur->text)).viewRect;
- if (mousePoint.v < viewRect.top) {
- DoScrollPart (cur->vScroll, inUpButton);
- ScrollToBar ();
- } else if (mousePoint.v > viewRect.bottom) {
- DoScrollPart (cur->vScroll, inDownButton);
- ScrollToBar ();
- }
- SetClip (saveClip);
- DisposeRgn (saveClip);
- }
- return (true);
- } /*AutoScroll*/
-